import request from '@/modules/index/utils/request';
import qs from "qs";
import { downloadFile } from '@/utils/common';


const store = {
    state: {
        // detectListRowData:{},
        // algoFileListRowData:{},
        // currentDetectLeftRowId:'', // 故障诊断-左列表点击当前行的id
        // currentPreviewLeftRowId:'', // 故障预测-左列表点击当前行的id
    },
    mutations: {
        // SET_DETECTLISTROWDATA: (state, data) => {
        //     state.detectListRowData = data
        // },
    },
    actions: {
        // 获取控件列表
        async getOperatorList() {
            const data = await request({
                url: '/dictionary/TreeList?dirCode=operatorType',
                // url: params ? `/algoTemplateFile/list?${params}` : '/algoTemplateFile/list',
                method: 'get'
            });
            return data;
        },
        // 执行算子
        async execOperator(context, params) {
            const data = await request({
                url: '/feOperator/exec',
                method: 'post',
                data: params,
                // paramsSerializer: (params) => {
                //     return qs.stringify(params, { indices: false });
                // },
            });
            return data;
        },
        // 根据算子id获取数据集内容
        async getDataListById(context, params) {
            const data = await request({
                url: `/feOperator/getCacheById?id=${params.id}&pageSize=${params.pageSize}&page=${params.page}`,
                method: 'get',
                // params:params,
                // paramsSerializer: (params) => {
                //     return qs.stringify(params, { indices: false });
                // },
            });
            return data;
        },
        // 根据算子id获取数据集内容-主成分分析
        async getPcaDataListById(context, id) {
            const data = await request({
                url: `/feOperator/getPcaDataById?id=${id}`,
                method: 'get',
                // params:params,
                // paramsSerializer: (params) => {
                //     return qs.stringify(params, { indices: false });
                // },
            });
            return data;
        },
        // 获取缺省值弹框左边显示内容
        async getPubDataList(context, params) {
            const data = await request({
                url: `/feDatafile/getFieldTreeByProcessId`,
                method: 'get',
                params: params,
                paramsSerializer: (params) => {
                    return qs.stringify(params, { indices: false });
                },
            });
            return data;
        },

        // 动态算子新增接口
        async addDynamicOperator(context, params) {
            const data = await request({
                url: `/feOperator/save`,
                method: 'post',
                data: params,
            });
            return data;
        },

        // 文件上传-上传并返回数据接口
        async uploadAnalyze(context, params) {
            const data = await request({
                url: `/feDatafile/uploadAnalyze?processingId=${params.processingId}&txtMethod=1`,
                method: 'post',
                data: params.formData,
                // headers: {
                // 'Content-Type': 'multipart/form-data;charset=UTF-8'
                // }
            });
            return data;
        },

        // 文件上传-确定按钮
        async postUpload(context, params) {
            const data = await request({
                url: `/feDatafile/analyzeSave?id=${params}`,
                method: 'post',
                // data: params.formData,
                // headers: {
                // 'Content-Type': 'multipart/form-data;charset=UTF-8'
                // }
            });
            return data;
        },

        // 缺省值处理-确定按钮
        async postMissing(context, params) {
            const data = await request({
                url: `/feMissingRule/saveOrUpdateBatchBfClear?key=${params.key}&value=${params.value}`,
                method: 'post',
                data: params.t,
            });
            return data;
        },

        // 重复值处理-确定按钮
        async postDuplication(context, params) {
            const data = await request({
                url: `/feDuplicateRule/saveOrUpdateBatchBfClear?key=${params.key}&value=${params.value}`,
                method: 'post',
                data: params.t,
            });
            return data;
        },

        // 数据标准化-确定按钮
        async postStandard(context, params) {
            const data = await request({
                url: `/feStandardRule/saveOrUpdateBatchBfClear?key=${params.key}&value=${params.value}`,
                method: 'post',
                data: params.t,
            });
            return data;
        },

        // 主成分分析-确定按钮
        async postPca(context, params) {
            const data = await request({
                url: `/fePcaRule/saveOrUpdateBatchBfClear?key=${params.key}&value=${params.value}`,
                method: 'post',
                data: params.t,
            });
            return data;
        },

        // 过滤处理-确定按钮
        async postFilter(context, params) {
            const data = await request({
                url: `/feFilterRule/saveOrUpdateBatchBfClear?key=${params.key}&value=${params.value}`,
                method: 'post',
                data: params.t,
            });
            return data;
        },

        // 属性生成处理-确定按钮
        async postAttr(context, params) {
            const data = await request({
                url: `/feAttributecreateRule/saveOrUpdateBatchBfClear?key=${params.key}&value=${params.value}`,
                method: 'post',
                data: params.t,
            });
            return data;
        },

        // 文件输出-确定按钮
        async postOutput(context, params) {
            const data = await request({
                url: `/feOperator/exportCacheData`,
                method: 'post',
                data: params,
                responseType: 'blob'
            });
            downloadFile(data);
            return data;
        },

        // 算子删除
        async deleteOperator(context, params) {
            const data = await request({
                url: `/feOperator/deleteByIds`,
                method: 'post',
                params: params,
                paramsSerializer: (params) => {
                    return qs.stringify(params, { indices: false });
                },
            });
            return data;
        },

        // 字典根据dirCode查询
        async getDicBydirCode(context, params) {
            const data = await request({
                url: `/dictionary/TreeList`,
                method: 'get',
                params: params,
                paramsSerializer: (params) => {
                    return qs.stringify(params, { indices: false });
                },
            });
            return data;
        },

        // 根据单行类型获取过滤条件
        async getConditionSelectionByType(context, params) {
            const data = await request({
                url: `/dictionaryParam/pageList`,
                method: 'get',
                params: params,
                paramsSerializer: (params) => {
                    return qs.stringify(params, { indices: false });
                },
            });
            return data;
        },

        // 过滤处理-根据算子id回显右边表格数据
        async getFilterTableByOperatorId(context, processingId) {
            const data = await request({
                url: `/feFilterRule/list?processingId=${processingId}`,
                method: 'get',
            });
            return data;
        },

        // 缺失值处理-根据算子id回显右边表格数据
        async getMissingTableByOperatorId(context, processingId) {
            const data = await request({
                url: `/feMissingRule/list?processingId=${processingId}`,
                method: 'get',
            });
            return data;
        },

        // 重复值处理-根据算子id回显右边表格数据
        async getDuplicateTableByOperatorId(context, processingId) {
            const data = await request({
                url: `/feDuplicateRule/list?processingId=${processingId}`,
                method: 'get',
            });
            return data;
        },

        // 属性生成-根据算子id回显 下面 表格数据
        async getAttributeTableByOperatorId(context, processingId) {
            const data = await request({
                url: `/feAttributecreateRule/list?processingId=${processingId}`,
                method: 'get',
            });
            return data;
        },

        // 数据标准化-根据算子id回显 右边 表格数据
        async getStandardTableByOperatorId(context, processingId) {
            const data = await request({
                url: `/feStandardRule/list?processingId=${processingId}`,
                method: 'get',
            });
            return data;
        },

        // 主成分分析-根据算子id回显 右边 表格数据
        async getPcaTableByOperatorId(context, processingId) {
            const data = await request({
                url: `/fePcaRule/list?processingId=${processingId}`,
                method: 'get',
            });
            return data;
        },

        // 文件上传-根据算子id回显 右边 表格数据
        async getInputTableByOperatorId(context, processingId) {
            const data = await request({
                url: `/feDatafile/getTreeByProcessId?processingId=${processingId}`,
                method: 'get',
            });
            return data;
        },

        // 根据画布id渲染动态算子
        async renderOperatorByCanvasId(context, canvasId) {
            const data = await request({
                url: `/feOperator/getTree?canvasId=${canvasId}`,
                method: 'get',
            });
            return data;
        },

        // 文件上传中全部删除
        async uploadFileDeleteAll(context, ids) {
            const data = await request({
                url: `/feDatafile/deleteByIds?ids=${ids}`,
                method: 'post',
            });
            return data;
        },

        // 根据画布id渲染动态算子
        async getOperatorExplain(context, type) {
            const data = await request({
                url: `/helpInfo/getTree?helpCode=${type}`,
                method: 'get',
            });
            return data;
        },
    }
};

export default store;
